package com.jcrj.action.flow;

import java.util.List;

import com.jcrj.action.BaseAction;
import com.jcrj.entity.OProcessHis;
import com.jcrj.entity.OProcessinstance;
import com.jcrj.entity.OUser;
import com.jcrj.entity.Subject;
import com.jcrj.service.WorkflowManagerService;

public class FlowHisAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7902927884952095669L;
	private WorkflowManagerService workflowManagerService;
	private String flowId;
	private List<OProcessHis> processList;
	private Subject subject;
	private String name;
	private List<Subject> subjectList;
	private Long totalCount;
	private Long pageCount;
	private String ids;

	public String flowLook() {
		try {
			this.processList = this.workflowManagerService.getProcessList(Integer.parseInt(this.flowId));
			for (OProcessHis his : this.processList) {
				if ("开始".equals(his.getStatus())) {
					his.setNodeName(his.getStatus());
				} else if ("退回".equals(his.getStatus())) {
					his.setNodeName("<font color='red'>" + his.getStatus() + "</font>");
				} else {
					String nodeName = this.workflowManagerService.getNodeName(his.getStartNode());
					his.setNodeName(nodeName);
				}

				his.setUserName(this.workflowManagerService.getUserName(his.getActors()));
				his.setEndNodeName(this.workflowManagerService.getNodeName(his.getEndNode()));
			}
			OProcessinstance instance = this.workflowManagerService.getProcessinstance(Integer.parseInt(this.flowId));
			if ((instance != null) && ("task".equals(instance.getNodeStatus()))) {
				OProcessHis current = new OProcessHis();
				current.setNodeName(this.workflowManagerService.getNodeName(instance.getNodeId()) + "<br><font color='red'>(未处理)</font>");
				current.setExecutor(this.workflowManagerService.getUserName(instance.getExecutor()));
				current.setStatus("未处理");
				this.processList.add(current);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
	}

	public String subjectList() {
		try {
			OUser ou = (OUser) super.getSession().get("userInfo");
			this.subjectList = this.workflowManagerService.getSubjectList(this.name, super.getCurrentPage(), ou.getId().intValue());
			this.totalCount = this.workflowManagerService.countSubject(this.name, ou.getId().intValue());
			this.pageCount = Long.valueOf((this.totalCount.longValue() - 1L) / 10L + 1L);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
	}

	public String saveSubject() {
		return "success";
	}

	public String subjectSave() {
		try {
			OUser ou = (OUser) super.getSession().get("userInfo");
			this.workflowManagerService.saveSubject(this.subject, ou);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String updateSubject() {
		try {
			this.subject = this.workflowManagerService.getSubject(Integer.parseInt(this.ids));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
	}

	public String subjectUpdate() {
		try {
			this.workflowManagerService.updateSubject(this.subject);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String deleteSubject() {
		try {
			this.workflowManagerService.deleteSubject(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String addSubjectOut() {
		OUser ou = (OUser) super.getSession().get("userInfo");
		this.subjectList = this.workflowManagerService.getDispatcherList(ou.getOrgId().intValue());
		return "success";
	}

	public List<OProcessHis> getProcessList() {
		return this.processList;
	}

	public void setProcessList(List<OProcessHis> processList) {
		this.processList = processList;
	}

	public WorkflowManagerService getWorkflowManagerService() {
		return this.workflowManagerService;
	}

	public void setWorkflowManagerService(WorkflowManagerService workflowManagerService) {
		this.workflowManagerService = workflowManagerService;
	}

	public String getFlowId() {
		return this.flowId;
	}

	public void setFlowId(String flowId) {
		this.flowId = flowId;
	}

	public Subject getSubject() {
		return this.subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Subject> getSubjectList() {
		return this.subjectList;
	}

	public void setSubjectList(List<Subject> subjectList) {
		this.subjectList = subjectList;
	}

	public Long getTotalCount() {
		return this.totalCount;
	}

	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}

	public Long getPageCount() {
		return this.pageCount;
	}

	public void setPageCount(Long pageCount) {
		this.pageCount = pageCount;
	}

	public String getIds() {
		return this.ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}
}

/*
 * Location: /Volumes/work/oa/WEB-INF/classes/ Qualified Name:
 * com.jcrj.action.flow.FlowHisAction JD-Core Version: 0.6.0
 */